package org.example.ssmioc1.config;

import ch.qos.logback.core.encoder.JsonEscapeUtil;
import org.example.ssmioc1.condition.WindowsCondition;
import org.example.ssmioc1.condition.macCondition;
import org.example.ssmioc1.pean.Person;
import org.springframework.context.annotation.*;

//配置类可以代替配置文件
//
//@Scope("singleton")//单实例只创建一次，在调用一次不用在创建新的一次
//@Scope("prototype")//因为在多实例下我们相当于懒汉式所有我们大多在单实例中配合使用
@Configuration
public class daoConfig {

    @Conditional(WindowsCondition.class)
    @Bean
    public Person Person(){
        Person person = new Person();
        person.setName("乔布斯");
        person.setAge(18);
        person.setSex("男");
        return person;
    }
    @Conditional(macCondition.class)
    @Bean//设置为默认
    public Person Person1(){
        Person person = new Person();
        person.setName("jobs");
        person.setAge(18);
        person.setSex("男");
        return person;
    }

    @Bean
    public Person zhangsan(){
        Person person = new Person();
        person.setName("张三");
        person.setAge(18);
        person.setSex("男");
        return person;
    }
    @Bean("car_alias")//在@Bean注解中添加别名在使用需要使用别名
    public Person car(){
        Person person = new Person();
        person.setName("张三");
        person.setAge(18);
        person.setSex("男");
        return person;
    }

}
